//
//  MyVipCourseViewController.m
//  Courses
//
//  Created by YiXuePxh on 15/4/3.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "MyVipCourseViewController.h"
#import "VipCourseClass.h"
#import "MyVipCell.h"
@interface MyVipCourseViewController ()

@end

@implementation MyVipCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //提示网络状态
    [self showNetStatus];
    //
    // Do any additional setup after loading the view.
    self.title = @"我的高级课";
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.items = [[VipCourseClass getCourseArray] mutableCopy];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
            NSLog(@"我的高级课%d",[self.items count]);
        });
    });
    //界面刷新
    UIRefreshControl* rc = [[UIRefreshControl alloc] init];
    [rc addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventValueChanged];
    rc.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"];
    self.refreshControl = rc;
    self.refreshControl.tintColor = [UIColor colorWithRed:16/255.0 green:101/255.0 blue:228/255.0 alpha:1.0];
}

- (void)refreshAction{
    NSLog(@"开始刷新！");
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.items = [[VipCourseClass getCourseArray] mutableCopy];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
            [self.refreshControl endRefreshing];
        });
    });
}
//界面刷新结束


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.items count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyVipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[MyVipCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        VipCourseClass* myVipCourse = self.items[indexPath.row];
        cell.course = myVipCourse;
    }
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
